﻿Public MustInherit Class RepositoryBase(Of T)

#Region "Events"

    Public Event DataAdded As EventHandler(Of DataEventArgs(Of T))
    Public Event DataRemoved As EventHandler(Of DataEventArgs(Of T))
    Public Event DataUpdated As EventHandler(Of DataUpdatedEventArgs(Of T))

    Protected Overridable Sub OnDataAdded(ByVal e As DataEventArgs(Of T))
        Dim handler As EventHandler(Of DataEventArgs(Of T)) = Me.DataAddedEvent
        If handler IsNot Nothing Then
            handler.Invoke(Me, e)
        End If
    End Sub

    Protected Overridable Sub OnDataRemoved(ByVal e As DataEventArgs(Of T))
        Dim handler As EventHandler(Of DataEventArgs(Of T)) = Me.DataRemovedEvent
        If handler IsNot Nothing Then
            handler.Invoke(Me, e)
        End If
    End Sub

    Protected Overridable Sub OnDataUpdated(ByVal e As DataUpdatedEventArgs(Of T))
        Dim handler As EventHandler(Of DataUpdatedEventArgs(Of T)) = Me.DataUpdatedEvent
        If handler IsNot Nothing Then
            handler.Invoke(Me, e)
        End If
    End Sub

#End Region

#Region "Properties"

    Protected _dataList As List(Of T)
    Protected Property InnerDataList() As List(Of T)
        Get
            Return _dataList
        End Get
        Set(ByVal value As List(Of T))
            _dataList = value
        End Set
    End Property

    Public ReadOnly Property Count() As Integer
        Get
            Return Me.InnerDataList.Count
        End Get
    End Property

#End Region

#Region "Constructors"

    Protected Sub New()
    End Sub

#End Region

#Region "Abstract Methods"

    Public MustOverride Sub Load()

    Public MustOverride Sub Save()

#End Region

End Class
